package features.advance.nowcoder.meituan;

import java.util.Arrays;

/**
 * 题目描述
 * 难度：中等
 * 在4x4的棋盘上摆满了黑白棋子，黑白两色的位置和数目随机其中左上角坐标为(1,1),右下角坐标为(4,4),
 * 现在依次有一些翻转操作，要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻转，
 * 请计算出翻转后的棋盘颜色。
 *
 * 给定两个数组A和f,分别为初始棋盘和翻转位置。其中翻转位置共有3个。请返回翻转后的棋盘。
 *
 * 测试样例：
 * [[0,0,1,1],[1,0,1,0],[0,1,1,0],[0,0,1,0]],[[2,2],[3,3],[4,4]]
 * 返回：[[0,1,1,1],[0,0,1,0],[0,1,1,0],[0,0,1,0]]
 *
 * @author LIN
 * @date 2021-05-19
 */
public class MT2 {
    public static void main(String[] args) {
        Flip flip = new Flip() {
        };
        int[][] A = {{0,1,0,0},{1,0,1,0},{1,1,0,0},{1,0,0,1}};
        int[][] f = {{2,3},{4,2},{2,3}};
        int[][] res = flip.flipChess(A, f);
        for (int i = 0; i < res.length; i++) {
            int[] re = res[i];
            System.out.println(Arrays.toString(re));
        }
        //[[0,1,0,0],[1,0,1,0],[1,0,0,0],[0,0,1,1]]
    }
}
class Flip {
    public int[][] flipChess(int[][] A, int[][] f) {
        // write code here
        for (int i = 0; i < f.length; i++) {
            int[] ints = f[i];
            int anInt = ints[0];
            int anInt1 = ints[1];
            if(anInt1 - 2>=0 && anInt1 - 2 <A.length && anInt - 1 < A.length && anInt - 1 >=0){
                System.out.println("("+(anInt)+","+(anInt1-1)+")");
                A[anInt-1][anInt1-2] ^=1;
            }
            if(anInt1 - 1 >=0 && anInt1-1 <A.length && anInt < A.length){
                System.out.println("("+(anInt+1)+","+(anInt1)+")");
                A[anInt][anInt1-1] ^=1;
            }
            if(anInt - 2 >=0 && anInt - 2 < A.length && anInt1 - 1<A.length && anInt1 - 1 >= 0){
                System.out.println("("+(anInt-1)+","+(anInt1)+")");
                A[anInt-2][anInt1-1] ^=1;
            }
            if(anInt - 1>=0 && anInt-1< A.length && anInt1 < A.length){
                System.out.println("("+(anInt)+","+(anInt1+1)+")");
                A[anInt-1][anInt1] ^=1;
            }
        }
        return A;
    }
}
